package com.tz.farmer.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tz.farmer.model.OperateInfo;
import com.tz.farmer.model.OperateInfoVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface OperateInfoMapper extends BaseMapper<OperateInfo> {

    @Select("<script>select o.*,b.city from operate_info o LEFT JOIN product_info p on o.p_info_id = p.id\n" +
            "LEFT JOIN business_info b on p.lead_id = b.id where o.p_info_id = #{pInfoId} limit #{n} , #{m} </script>")
    List<OperateInfoVo> selectListByPid(@Param("n") int n,@Param("m") int m,@Param("pInfoId") Integer pInfoId);

    @Select("<script>select count(0) from operate_info o LEFT JOIN product_info p on o.p_info_id = p.id\n" +
            "LEFT JOIN business_info b on p.lead_id = b.id where o.p_info_id = #{pInfoId}</script>")
    int selectCountByPid(@Param("pInfoId")Integer pInfoId);

    @Select("<script>select \n" +
            "o.o_type as oType,\n" +
            "o.p_name as pName,\n" +
            "o.in_thing as inThing,\n" +
            "o.o_time \n" +
            "from business_info b left join product_info p \n" +
            "on b.id = p.lead_id\n" +
            "LEFT JOIN operate_info o\n" +
            "on o.p_info_id = p.id\n" +
            "LEFT JOIN trade_info t \n" +
            "on t.p_info_id = o.p_info_id\n" +
            "LEFT JOIN detection_info d\n" +
            "on d.p_info_id = t.p_info_id\n" +
            "where\n" +
            "b.property = 331002 \n" +
            "and\n" +
            "b.unisc_id = #{certificateCode}\n" +
            "and\n" +
            "p.p_name = #{goodsName}\n" +
            "and\n" +
            "o.p_name = #{goodsName}\n" +
            "and\n" +
            "t.trade_time = DATE_FORMAT(FROM_UNIXTIME(#{tradeTime}/1000,'%Y-%m-%d %h:%i:%s'),'%Y-%m-%d')</script>")
        List<OperateInfoVo> selectOperateByNameList(@Param("goodsName") String goodsName,@Param("certificateCode") String certificateCode, @Param("tradeTime") String tradeTime);

    @Select("select *  from operate_info where p_info_id =#{pid} and p_name=#{goodsName}")
    List<OperateInfoVo> selectOperateList(@Param("pid")Integer pid, @Param("goodsName")String goodsName);

    @Select("select *  from add_link where shxydm =#{uniscId}")
    Map selectAddLink(@Param("uniscId")String uniscId);

    @Select("select * from quick_scan where product_id =#{id}" )
    Map<String,Object> selectQuickScan(@Param("id") int id);
}
